package com.gisuni.sddc.service;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.gisuni.sddc.dao.LandStatisticsDao;
import com.gisuni.sddc.model.Response;
import com.gisuni.sddc.util.ExcelOperation;

@IocBean
public class LandStatisticsService {

	private Log log = LogFactory.getLog(LandStatisticsService.class);
	@Inject
	private LandStatisticsDao landStatisticsDao;

	/**
	 * 统计制定时间段内各拓展组的登记情况
	 * 
	 * @param
	 * @return
	 */
	public Response queryOrganizationList(String departmentType, String projectType, String startdate, String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String OrgResult = null;
		String LandResult = null;
		String selectstr = "";
		try {

			selectstr = "select tc.organization_name company,tb.organization_name department,tt.organization_name team,         "
					+ "       (select tu.displayname from SDDCONEMAP.USERINFO tu where tu.userid = tt.organization_manager_id) teamleader"
					+ "  from SDDCGISPLATFORM.ORGANIZATION tt, SDDCGISPLATFORM.ORGANIZATION tb, SDDCGISPLATFORM.ORGANIZATION tc                                               "
					+ " where tt.parent_id = tb.id and tb.parent_id = tc.id                                                   ";
			OrgResult = landStatisticsDao.queryResultList(selectstr);

			if (OrgResult == null) {
				return response;
			}
			response.setSuccess(true);
			// LandResult = queryLandList(projectType, startdate,
			// enddate).getResult().toString();
			// JSONObject ret=new JSONObject();
			// ret.put("org", OrgResult);
			// ret.put("land", LandResult);
			// JSONArray result=new JSONArray();
			// result.put(ret);
			response.setResult(OrgResult);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}

	/**
	 * 统计制定时间段内各拓展组的登记情况
	 * 
	 * @param
	 * @return
	 */
	public Response queryLandList(String projectType, String startdate, String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String Result = null;
		String selectstr = "";
		try {

			selectstr = "select t.objectid,                                          "
					+ "       t.xh,                                                "
					+ "       t.type,                                              "
					+ "       tz.organization_name team,                           "
					+ "       tb.organization_name department,                     "
					+ "       tc.organization_name company                         "
					+ "  from SDDCGISPLATFORM.LANDEXPAND        t,                                 "
					+ "       SDDCGISPLATFORM.USER_ORGANIZATION t2,                                "
					+ "       SDDCONEMAP.USERINFO          t1,                                "
					+ "       SDDCGISPLATFORM.ORGANIZATION      tz,                                "
					+ "       SDDCGISPLATFORM.ORGANIZATION      tb,                                "
					+ "       SDDCGISPLATFORM.ORGANIZATION      tc                                 "
					+ " where t.registeruser = t2.user_id(+)                       "
					+ "   and t.registeruser = t1.userid(+)                        "
					+ "   and tz.id = t2.organization_develop_id                   "
					+ "   and tb.id = t2.organization_business_id                  "
					+ "   and tc.id = t2.organization_company_id                   " + "   and t.type = '" + projectType
					+ "'                           " + "   and t.registerdate >= to_date('" + startdate
					+ "', 'yyyy-mm-dd')" + "   and t.registerdate <= to_date('" + enddate + "', 'yyyy-mm-dd') "
					+ "order by tc.organization_name,tb.organization_name,tz.organization_name";
			Result = landStatisticsDao.queryResultList(selectstr);

			if (Result == null) {
				return response;
			}
			response.setSuccess(true);
			response.setResult(Result);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}

	/**
	 * 统计制定时间段内各拓展组的登记情况
	 * 
	 * @param
	 * @return
	 */
	public Response queryAndStatisticsLandByTeam(String departmentType, String projectType, String startdate,
			String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String Result = null;
		String selectstr = "";
		try {

			selectstr = " select tf.company,tf.department,tf.team,th.teamleader,th.pnum,'2' zhibiao,(NVL(th.pnum,0)/2)*100 wcd from     "
					+ " (select tc.organization_name company,tb.organization_name department,tt.organization_name team ,tt.id teamid from  "
					+ "          SDDCGISPLATFORM.ORGANIZATION tt,                                                                                          "
					+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                          "
					+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                           "
					+ "    where tt.parent_id = tb.id                                                                                      "
					+ "      and tb.parent_id = tc.id) tf,                                                                                 "
					+ " (select tg.company,tg.department,tg.teamid,tg.team,tg.teamleader,count(tg.team) pnum from                          "
					+ "    (select t.objectid,                                                                                             "
					+ "          t.xh,                                                                                                     "
					+ "          t.type,                                                                                                   "
					+ "          t.registeruser,                                                                                           "
					+ "          t1.displayname,                                                                                           "
					+ "          tz.organization_name team,                                                                                "
					+ "          tz.id teamid,                                                                                             "
					+ "          (select tu.displayname                                                                                    "
					+ "             from SDDCONEMAP.USERINFO tu                                                                                       "
					+ "            where tu.userid = tz.organization_manager_id) teamleader,                                               "
					+ "          tb.organization_name department,                                                                          "
					+ "          tb.id departmentid,                                                                                       "
					+ "          tc.organization_name company,                                                                             "
					+ "          tc.id companyid                                                                                           "
					+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                             "
					+ "          SDDCGISPLATFORM.USER_ORGANIZATION t2,                                                                                     "
					+ "          SDDCONEMAP.USERINFO t1,                                                                                              "
					+ "          SDDCGISPLATFORM.ORGANIZATION tz,                                                                                          "
					+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                          "
					+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                           "
					+ "    where t.registeruser = t2.user_id(+)                                                                            "
					+ "      and t.registeruser = t1.userid(+)                                                                             "
					+ "      and tz.id = t2.organization_develop_id                                                                        "
					+ "      and tb.id = t2.organization_business_id                                                                       "
					+ "      and tc.id = t2.organization_company_id                                                                        "
					+ "      and t.type = '" + projectType + "'                                         "
					+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
					+ "      and t.registerdate <= to_date('" + enddate + "', 'yyyy-mm-dd')) tg         "
					+ "      group by tg.teamid,tg.team,tg.teamleader,tg.department,tg.company) th                                         "
					+ "      where tf.teamid = th.teamid(+) order by wcd desc                                                              ";
			Result = landStatisticsDao.queryAndStatisticsLandByTeam(selectstr);

			if (Result == null) {
				return response;
			}
			response.setSuccess(true);
			response.setResult(Result);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}

	/**
	 * 统计制定时间段内各事业部的登记情况
	 * 
	 * @param
	 * @return
	 */
	public Response queryAndStatisticsLandByDepartment(String departmentType, String projectType, String startdate,
			String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String Result = null;
		String selectstr = "";
		try {

			selectstr = "  select tf.company,tf.department,tf.gnum, tt.pnum,tf.gnum*2 zhibiao,ROUND((NVL(tt.pnum,0)/(tf.gnum*2))*100,1) wcd  from    "
					+ " (select t2.organization_name company, t1.organization_name department,t1.id departmentid,tb.gnum                                       "
					+ "                  from SDDCGISPLATFORM.ORGANIZATION t1,                                                                                                 "
					+ "                       SDDCGISPLATFORM.ORGANIZATION t2,                                                                                                 "
					+ "                       (select t3.parent_id, count(t3.parent_id) gnum                                                                   "
					+ "                          from SDDCGISPLATFORM.ORGANIZATION t3                                                                                          "
					+ "                         where t3.organization_type = '3'                                                                               "
					+ "                         group by t3.parent_id) tb                                                                                      "
					+ "                 where t1.id = tb.parent_id                                                                                             "
					+ "                   and t2.id = t1.parent_id                                                                                             "
					+ "                   and t1.organization_type = '2')tf,                                                                                   "
					+ " (select tg.company,tg.department,tg.departmentid,count(tg.department) pnum from                                                        "
					+ "    (select t.objectid,                                                                                                                 "
					+ "          t.xh,                                                                                                                         "
					+ "          t.type,                                                                                                                       "
					+ "          t.registeruser,                                                                                                               "
					+ "          t1.displayname,                                                                                                               "
					+ "          tb.organization_name department,                                                                                              "
					+ "          tb.id departmentid,                                                                                                           "
					+ "          tc.organization_name company                                                                                                  "
					+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                                                 "
					+ "          SDDCGISPLATFORM.USER_ORGANIZATION t2,                                                                                                         "
					+ "          SDDCONEMAP.USERINFO t1,                                                                                                                  "
					+ "          SDDCGISPLATFORM.ORGANIZATION tz,                                                                                                              "
					+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                                              "
					+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                                               "
					+ "    where t.registeruser = t2.user_id(+)                                                                                                "
					+ "      and t.registeruser = t1.userid(+)                                                                                                 "
					+ "      and tz.id = t2.organization_develop_id                                                                                            "
					+ "      and tb.id = t2.organization_business_id                                                                                           "
					+ "      and tc.id = t2.organization_company_id                                                                                            "
					+ "      and t.type = '" + projectType + "'                                         "
					+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
					+ "      and t.registerdate <= to_date('" + enddate
					+ "', 'yyyy-mm-dd')) tg                                                                     "
					+ "      group by tg.department,tg.departmentid,tg.company) tt                                                                             "
					+ "      where tf.departmentid = tt.departmentid(+) order by wcd desc                                                                     ";

			Result = landStatisticsDao.queryAndStatisticsLandByTeam(selectstr);

			if (Result == null) {
				return response;
			}
			response.setSuccess(true);
			response.setResult(Result);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}

	/**
	 * 统计制定时间段内各集团公司的登记情况
	 * 
	 * @param
	 * @return
	 */
	public Response queryAndStatisticsLandByCompany(String departmentType, String projectType, String startdate,
			String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String Result = null;
		String selectstr = "";
		try {

			selectstr = "  select tf.organization_name company,tf.gnum,th.pnum,tf.gnum*2 zhibiao, ROUND((NVL(th.pnum,0)/(tf.gnum*2))*100,1) wcd "
					+ "  from (select t5.*, t4.organization_name                                                                                       "
					+ "             from (select t.parent_id, sum(t.gnum) gnum                                                                         "
					+ "                     from (select t1.id,                                                                                        "
					+ "                                  t1.organization_name,                                                                         "
					+ "                                  t1.parent_id,                                                                                 "
					+ "                                  tb.gnum                                                                                       "
					+ "                             from SDDCGISPLATFORM.ORGANIZATION t1,                                                                              "
					+ "                                  (select t3.parent_id,                                                                         "
					+ "                                          count(t3.parent_id) gnum                                                              "
					+ "                                     from SDDCGISPLATFORM.ORGANIZATION t3                                                                       "
					+ "                                    where t3.organization_type = '3'                                                            "
					+ "                                    group by t3.parent_id) tb                                                                   "
					+ "                            where t1.id = tb.parent_id                                                                          "
					+ "                              and t1.organization_type = '2') t                                                                 "
					+ "                    group by t.parent_id) t5,                                                                                   "
					+ "                  ORGANIZATION t4                                                                                               "
					+ "            where t4.id = t5.parent_id) tf,                                                                                     "
					+ "  (select tg.companyid,tg.company,count(tg.company) pnum from                                                                   "
					+ "    (select tc.id companyid,                                                                                                    "
					+ "    tc.organization_name company                                                                                                "
					+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                                         "
					+ "          SDDCGISPLATFORM.USER_ORGANIZATION t2,                                                                                                 "
					+ "          SDDCONEMAP..USERINFO t1,                                                                                                          "
					+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                                       "
					+ "    where t.registeruser = t2.user_id(+)                                                                                        "
					+ "      and t.registeruser = t1.userid(+)                                                                                         "
					+ "      and tc.id = t2.organization_company_id                                                                                    "
					+ "      and t.type = '" + projectType + "'                                         "
					+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
					+ "      and t.registerdate <= to_date('" + enddate
					+ "', 'yyyy-mm-dd')) tg                                                            "
					+ "      group by tg.companyid,tg.company) th                                                                                      "
					+ "      where tf.parent_id = th.companyid(+) order by wcd desc                                                                                     ";
			Result = landStatisticsDao.queryAndStatisticsLandByTeam(selectstr);

			if (Result == null) {
				return response;
			}
			response.setSuccess(true);
			response.setResult(Result);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}

	public void exportlandStatistics(String departmentType, String projectType, String startdate, String enddate,
			HttpServletResponse response) throws Exception {
		
		String filetitle = null;
		String[] rowsName = null;
		String[] columnTop = null;
		String rowTitle="";
		if("mocha".equals(projectType)){
			projectType="核查项目";
			rowTitle="摸查地块数";
		}else if("qiatan".equals(projectType)){
			projectType="洽谈项目";
			rowTitle="洽谈项目数";
		}else if("huoqu".equals(projectType)){
			projectType="获取项目";
			rowTitle="获取项目数";
		}
		Response responseStr = getExportResponse(departmentType, projectType, startdate, enddate);
		if ("company".equals(departmentType)) {
			filetitle = "公司、集团"+projectType;
			rowsName = new String[] { "排名", "城市",   rowTitle, "任务指标", "完成度" };
			columnTop = new String[] { "", "COMPANY",   "PNUM", "ZHIBIAO", "WCD" };
		} else if ("department".equals(departmentType)) {
			filetitle = "事业部"+projectType;
			rowsName = new String[] { "排名", "城市","事业部","小组数",   rowTitle, "任务指标", "完成度" };
			columnTop = new String[] { "", "COMPANY", "DEPARTMENT","GNUM",  "PNUM", "ZHIBIAO", "WCD" };
		} else if ("teamgroup".equals(departmentType)) {
			filetitle = "扩展组"+projectType;
			rowsName = new String[] { "排名", "城市", "事业部","扩展组", "组长", rowTitle, "任务指标", "完成度" };
			columnTop = new String[] { "", "COMPANY", "DEPARTMENT","TEAM","TEAMLEADER",  "PNUM", "ZHIBIAO", "WCD" };
		}
//		if(responseStr.getResult().)
		String resultStr = (String) responseStr.getResult();
		JSONArray resultJsonArr = new JSONArray(resultStr);
		resultJsonArr.length();
		List<Map> Result = new ArrayList<Map>();
		if (resultJsonArr != null && resultJsonArr.length() > 0) {

			for (int i = 0; i < resultJsonArr.length(); i++) {
				JSONObject ret = (JSONObject) resultJsonArr.get(i);
				Iterator iterator = ret.keys();
				Map map = new HashMap();
				while (iterator.hasNext()) {
					String key = (String) iterator.next();
					String value = (String) ret.get(key);
					if("WCD".equals(key)){
				      value=value+"%";
					}
					map.put(key, value);
				}
				Result.add(map);
			}
		}
		ExcelOperation excle = new ExcelOperation();
		excle.export(filetitle, rowsName, columnTop, Result, response);
	}

 
	public Response getExportResponse(String departmentType, String projectType, String startdate, String enddate) {

		Response response = new Response();
		response.setSuccess(false);
		String Result = null;
		String selectstr = "";
		try {
			if ("company".equals(departmentType)) {
				selectstr = "  select tf.organization_name company,tf.gnum,th.pnum,tf.gnum*2 zhibiao, ROUND((NVL(th.pnum,0)/(tf.gnum*2))*100,1) wcd "
						+ "  from (select t5.*, t4.organization_name                                                                                       "
						+ "             from (select t.parent_id, sum(t.gnum) gnum                                                                         "
						+ "                     from (select t1.id,                                                                                        "
						+ "                                  t1.organization_name,                                                                         "
						+ "                                  t1.parent_id,                                                                                 "
						+ "                                  tb.gnum                                                                                       "
						+ "                             from SDDCGISPLATFORM.ORGANIZATION t1,                                                                              "
						+ "                                  (select t3.parent_id,                                                                         "
						+ "                                          count(t3.parent_id) gnum                                                              "
						+ "                                     from SDDCGISPLATFORM.ORGANIZATION t3                                                                       "
						+ "                                    where t3.organization_type = '3'                                                            "
						+ "                                    group by t3.parent_id) tb                                                                   "
						+ "                            where t1.id = tb.parent_id                                                                          "
						+ "                              and t1.organization_type = '2') t                                                                 "
						+ "                    group by t.parent_id) t5,                                                                                   "
						+ "                  SDDCGISPLATFORM.ORGANIZATION t4                                                                                               "
						+ "            where t4.id = t5.parent_id) tf,                                                                                     "
						+ "  (select tg.companyid,tg.company,count(tg.company) pnum from                                                                   "
						+ "    (select tc.id companyid,                                                                                                    "
						+ "    tc.organization_name company                                                                                                "
						+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                                         "
						+ "          SDDCGISPLATFORM.USER_ORGANIZATION t2,                                                                                                 "
						+ "          SDDCONEMAP.USERINFO t1,                                                                                                          "
						+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                                       "
						+ "    where t.registeruser = t2.user_id(+)                                                                                        "
						+ "      and t.registeruser = t1.userid(+)                                                                                         "
						+ "      and tc.id = t2.organization_company_id                                                                                    "
						+ "      and t.type = '" + projectType + "'                                         "
						+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
						+ "      and t.registerdate <= to_date('" + enddate
						+ "', 'yyyy-mm-dd')) tg                                                            "
						+ "      group by tg.companyid,tg.company) th                                                                                      "
						+ "      where tf.parent_id = th.companyid(+) order by wcd desc ";
			} else if ("department".equals(departmentType)) {

				selectstr = "  select tf.company,tf.department,tf.gnum, tt.pnum,tf.gnum*2 zhibiao,ROUND((NVL(tt.pnum,0)/(tf.gnum*2))*100,1)  wcd  from    "
						+ " (select t2.organization_name company, t1.organization_name department,t1.id departmentid,tb.gnum                                       "
						+ "                  from SDDCGISPLATFORM.ORGANIZATION t1,                                                                                                 "
						+ "                       SDDCGISPLATFORM.ORGANIZATION t2,                                                                                                 "
						+ "                       (select t3.parent_id, count(t3.parent_id) gnum                                                                   "
						+ "                          from SDDCGISPLATFORM.ORGANIZATION t3                                                                                          "
						+ "                         where t3.organization_type = '3'                                                                               "
						+ "                         group by t3.parent_id) tb                                                                                      "
						+ "                 where t1.id = tb.parent_id                                                                                             "
						+ "                   and t2.id = t1.parent_id                                                                                             "
						+ "                   and t1.organization_type = '2')tf,                                                                                   "
						+ " (select tg.company,tg.department,tg.departmentid,count(tg.department) pnum from                                                        "
						+ "    (select t.objectid,                                                                                                                 "
						+ "          t.xh,                                                                                                                         "
						+ "          t.type,                                                                                                                       "
						+ "          t.registeruser,                                                                                                               "
						+ "          t1.displayname,                                                                                                               "
						+ "          tb.organization_name department,                                                                                              "
						+ "          tb.id departmentid,                                                                                                           "
						+ "          tc.organization_name company                                                                                                  "
						+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                                                 "
						+ "          SDDCGISPLATFORM.USER_ORGANIZATION t2,                                                                                                         "
						+ "          SDDCONEMAP.USERINFO t1,                                                                                                                  "
						+ "          SDDCGISPLATFORM.ORGANIZATION tz,                                                                                                              "
						+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                                              "
						+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                                               "
						+ "    where t.registeruser = t2.user_id(+)                                                                                                "
						+ "      and t.registeruser = t1.userid(+)                                                                                                 "
						+ "      and tz.id = t2.organization_develop_id                                                                                            "
						+ "      and tb.id = t2.organization_business_id                                                                                           "
						+ "      and tc.id = t2.organization_company_id                                                                                            "
						+ "      and t.type = '" + projectType + "'                                         "
						+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
						+ "      and t.registerdate <= to_date('" + enddate
						+ "', 'yyyy-mm-dd')) tg                                                                     "
						+ "      group by tg.department,tg.departmentid,tg.company) tt                                                                             "
						+ "      where tf.departmentid = tt.departmentid(+) order by wcd desc                                                                     ";
			} else if ("teamgroup".equals(departmentType)) {
				selectstr = " select tf.company,tf.department,tf.team,tf.teamleader,th.pnum,'2' zhibiao,(NVL(th.pnum,0)/2)*100  wcd from     "
						+ " (select tc.organization_name company,tb.organization_name department,tt.organization_name team ,tt.id teamid,"
						+ "(select tu.displayname from SDDCONEMAP.USERINFO tu where tu.userid = tt.organization_manager_id) teamleader  from  "
                           
                          
						+ "          SDDCGISPLATFORM.ORGANIZATION tt,                                                                                          "
						+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                          "
						+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                           "
						+ "    where tt.parent_id = tb.id                                                                                      "
						+ "      and tb.parent_id = tc.id) tf,                                                                                 "
						+ " (select tg.company,tg.department,tg.teamid,tg.team,count(tg.team) pnum from                          "
						+ "    (select t.objectid,                                                                                             "
						+ "          t.xh,                                                                                                     "
						+ "          t.type,                                                                                                   "
						+ "          t.registeruser,                                                                                           "
						+ "          t1.displayname,                                                                                           "
						+ "          tz.organization_name team,                                                                                "
						+ "          tz.id teamid,                                                                                             "
						+ "          tb.organization_name department,                                                                          "
						+ "          tb.id departmentid,                                                                                       "
						+ "          tc.organization_name company,                                                                             "
						+ "          tc.id companyid                                                                                           "
						+ "     from SDDCGISPLATFORM.LANDEXPAND t,                                                                                             "
						+ "          SDDCGISPLATFORMUSER_ORGANIZATION t2,                                                                                     "
						+ "          SDDCONEMAP.USERINFO t1,                                                                                              "
						+ "          SDDCGISPLATFORM.ORGANIZATION tz,                                                                                          "
						+ "          SDDCGISPLATFORM.ORGANIZATION tb,                                                                                          "
						+ "          SDDCGISPLATFORM.ORGANIZATION tc                                                                                           "
						+ "    where t.registeruser = t2.user_id(+)                                                                            "
						+ "      and t.registeruser = t1.userid(+)                                                                             "
						+ "      and tz.id = t2.organization_develop_id                                                                        "
						+ "      and tb.id = t2.organization_business_id                                                                       "
						+ "      and tc.id = t2.organization_company_id                                                                        "
						+ "      and t.type = '" + projectType + "'                                         "
						+ "      and t.registerdate >= to_date('" + startdate + "', 'yyyy-mm-dd')           "
						+ "      and t.registerdate <= to_date('" + enddate + "', 'yyyy-mm-dd')) tg         "
						+ "      group by tg.teamid,tg.team,tg.department,tg.company) th  "
						+ "      where tf.teamid = th.teamid(+) order by wcd desc   ";
			}

			Result = landStatisticsDao.queryAndStatisticsLandByTeam(selectstr);

			if (Result == null) {
				return response;
			}
			response.setSuccess(true);
			response.setResult(Result);
			return response;
		} catch (Exception e) {
			log.error(e.getMessage());
			return response;
		}
	}
}
